<template>
    <div class="box">
        <headers title="分类"></headers>

        <van-row style="overflow: hidden;flex: 1;">
            <van-col span="6" style="overflow: auto;height: 100%;">
                <van-sidebar v-model="active">
                    <van-sidebar-item v-for="(v, i) in list" :key="i" :title="v.cat_name" />
                </van-sidebar>
            </van-col>

            <van-col span="18" style="overflow: auto;height: 100%;">
                <van-pull-refresh v-model="loading" @refresh="onRefresh">
                    <div v-for="(v, i) in list[active]?.children" :key="i">
                        <van-grid :border="false" :column-num="2">
                            <div>{{ v.cat_name }}</div>
                            <van-grid-item v-for="(val, index) in v.children" :key="index"
                                @click="tosearch(val.cat_name)">
                                <lazy-component>
                                    <img v-lazy="val.cat_icon" />
                                </lazy-component>
                                <p>{{ val.cat_name }}</p>
                                <!-- <van-image src="https://fastly.jsdelivr.net/npm/@vant/assets/apple-1.jpeg" /> -->
                            </van-grid-item>
                        </van-grid>
                    </div>
                </van-pull-refresh>


            </van-col>
        </van-row>


    </div>
</template>

<script setup>
import { ref } from "vue";
import { swiperdataApi, catitemsApi, categoriesApi, searchApi, detailApi } from "@/api/api";
import { useRoute, useRouter } from 'vue-router'

const router = useRouter()
const route = useRoute()

import headers from "@/components/headers.vue";

const active = ref(0);

let list = ref([]);
const getcategoriesApi = () => {
    categoriesApi().then((res) => {
        list.value = res.data.message;
    })
}
getcategoriesApi();

const tosearch = (name) => {
    router.push({
        path: '/search',
        query: { name: name }
    })
}

//下拉刷新
import { showToast } from 'vant';
const loading = ref(false);
const onRefresh = () => {
    setTimeout(() => {
        showToast('刷新成功');
        loading.value = false;
        // count.value++;
        getcategoriesApi();
    }, 1000);
};

</script>

<style lang="scss" scoped>
.box {
    width: 100%;
    height: 100%;
    overflow: auto;

    display: flex;
    flex-direction: column;
}
</style>